<?php
namespace Modules\ShopAdmin\Http\Controllers;
use Illuminate\Http\Request;
use Modules\ShopAdmin\Models\ShopRechargeLog as ShopRechargeLogModel;
class RechargeLogController extends CommonShopController
{
	/**
	 * @name  列表
	 */
    public function index()
    { 
        return view('shopadmin::recharge_log.index');
    }
	/**
	 * @name  列表数据
	 */
    public function data(Request $request)
    {
	    $model = ShopRechargeLogModel::query();
		$params = $request->all();
		$params['status'] = 1;
		$params_data = $params;
		unset($params['key']);
		$model = query_condition($model,$params); 
        $res = $model->select('id','updated_at','user_id','total_money','order_no','deliver_money')
				->whereHas('user_to',function($query)use($params_data){
					if(!empty($params_data['key'])){
						$query->where('phone', 'like', '%' . $params_data['key'] . '%');
						$query->orWhere('nick_name', 'like', '%' . $params_data['key'] . '%');
					}
				})
				->with([
					'user_to'=>function($query){
						$query->select('id','nick_name','phone');
					}
				])
				->orderBy('id','desc')  
				->paginate($params['limit'])
				->toArray();
		foreach($res['data'] as $k=>$v){
			$res['data'][$k]['nick_name'] = $v['user_to']['nick_name'];
			$res['data'][$k]['phone'] = $v['user_to']['phone'];
			unset($res['data'][$k]['user_to'],$res['data'][$k]['user_id']);
		}		
        return response()->json(['code' => 0, 'msg'   => config('admin.limit_msg'),'count' => $res['total'],'data'  => $res['data'],'rel'=>1]);
    }
}
